<?
// UltraMemo Project - GG_ShowQuestion.php
//      Get next question and output json for google gadget (igoogle)
//
// 11/17/09 initial creation - Scott Szretter

//get the questions that need to be reviewed
$GData->GDataQueryString=('nextreviewdt<='.date("m/d/Y 23:59:59"));
$listFeed=$GData->getWkshtListFeed();
//yes, we have at least one
if ( count($listFeed->entries) > 0) {
    //get the first row
    
    $row = $listFeed->entries[0];


    if(is_object($row))
    {
        $GData->QuestionsAvailable = TRUE;
        $rowData = $row->getCustom();

    foreach($rowData as $customEntry) {  //loop columns
        if ($customEntry->getColumnName()=="question") {
            $question = $customEntry->getText();
        } // if customentry = question
        if ($customEntry->getColumnName()=="hint") {
            $hint = $customEntry->getText();
        } // if customentry = hint
        if ($customEntry->getColumnName()=="answer") {
            $answer = $customEntry->getText();
        } // if customentry = user
         if ($customEntry->getColumnName()=="qid") { //question id
             $qid = $customEntry->getText();
         } // if column = qid
           if ($customEntry->getColumnName()=="topicdesc") {
             $topicdesc = $customEntry->getText();
         } // if column = topicdesc
    } //foreach customentry (columns)


    $JSONOutput.='"q":"'.$question.'"';
    $JSONOutput.=',"r":"'.count($listFeed->entries).'"'; //remaining questions
    if(strlen($hint)>0) $JSONOutput.=',"h":"'.$hint.'"';
    if(strlen($topicdesc)>0) $JSONOutput.=',"t":"'.$topicdesc.'"';
    if(strlen($answer)>0) $JSONOutput.=',"a":"'.$answer.'"';
    if($qid>0)
        {
            $JSONOutput.=',"i":"'.$qid.'"';
            $JSONOutput.=',"p":"1"'; //prompt -- did you have the correct answer?
        }
    } //is_object $row
    else
    {
    $GData->QuestionsAvailable = FALSE;
    $JSONOutput='"e":"1"'; //no more questions for today
    }
} // if count listfeed
else //no questions
{
    $GData->QuestionsAvailable = FALSE;
    $JSONOutput='"e":"1"'; //no more questions for today
}
?>